import socket
import socketserver
import logging

# class SyslogUDPHandler(socketserver.BaseRequestHandler):
#
#     def handle(self):
#         data = bytes.decode(self.request[0].strip())
#         socket = self.request[1]
#         print( "%s : " % self.client_address[0], str(data))
#         logging.info(str(data))
# #        socket.sendto(data.upper(), self.client_address)
#
#
# print(2)
# try:
#     server1 = socketserver.UDPServer(('0.0.0.0', 514), SyslogUDPHandler)
#     server1.serve_forever(poll_interval=0.5)
#     print(3)
# except Exception as e:
#     print(e)

server = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
server.bind(('0.0.0.0',514))

while True:
    try:
        data = server.recvfrom(8092)
        (LogMsg, host) = data
        LogMsg = LogMsg.decode('utf-8')
        print(LogMsg)
    except Exception as e:
        print(e)